package cn.singno.bob.jpa.annotation.core;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>名称：SearchFilterBeanBuilder.java</p>
 * <p>描述：</p>
 * <pre>
 *    
 * </pre>
 * @author 鲍建明
 * @date 2014年11月6日 下午4:36:06
 * @version 1.0.0
 */
public class SearchBuilder {
	
	private static ThreadLocal<List<SearchFilterBean>> seachBean = new ThreadLocal<List<SearchFilterBean>>();

	private static SearchBuilder builder = null;
	
	/**
	 * 
	 * <p>描述：构造器</p>
	 * <pre>
	 *    
	 * </pre>
	 * @return
	 */
	public static synchronized SearchBuilder newInstance(){
		if(builder == null){
			builder = new SearchBuilder();
			seachBean.set(new ArrayList<SearchFilterBean>());
		}
		return builder;
	}
	
	/**
	 * 
	 * <p>描述：构建一个查询对象</p>
	 * <pre>
	 *    
	 * </pre>
	 * @param fieldName
	 * @param operator
	 * @param value
	 * @return
	 */
	public  SearchBuilder append(String fieldName, SearchOperator operator, Object value){
		seachBean.get().add(new SearchFilterBean(fieldName, operator, value));
		return this;
	}
	
	/**
	 * 
	 * <p>描述：</p>
	 * <pre>
	 *    
	 * </pre>
	 * @param fieldName
	 * @param operator
	 * @param values
	 * @return
	 */
	public  SearchBuilder builder(String fieldName, SearchOperator operator, List<Object> values){
		 seachBean.get().add(new SearchFilterBean(fieldName, operator, values));
		 return this;
	}
	
	
	public  SearchBuilder builderEQ(String fieldName, Object value){
		seachBean.get().add(new SearchFilterBean(fieldName, SearchOperator.EQ, value));
		return this;
	}
	
	
	public  SearchBuilder builderLIKE(String fieldName, Object value){
		seachBean.get().add(new SearchFilterBean(fieldName, SearchOperator.LIKE, value));
		return this;
	}
	
	
	public  SearchBuilder builderIN(String fieldName, List<Object> values){
		seachBean.get().add(new SearchFilterBean(fieldName, SearchOperator.IN, values));
		return this;
	}
	

	
	
	public List<SearchFilterBean> toSearch(){
		return seachBean.get();
	}
	
	
}
